package glavni;

import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JToolBar;

public class MenadzerToolBar extends JToolBar {

	Menadzer menadzer;

	public MenadzerToolBar(Menadzer m) {
		menadzer = m;
		String[] imageFiles = { "document-new.png", "document-open.png",
				"document-save.png", "document-save-as.png", "go-first.png",
				"go-previous.png", "go-next.png", "go-last.png" };
		String[] toolbarLabels = { "Izaberi", "Otvori fajl...", "Snimi",
				"Snimi kao...", "Na pocetak/pokreni simulaciju", "Korak nazad",
				"Korak napred", "Na kraj" };
		Insets margins = new Insets(0, 0, 0, 0);
		for (int i = 0; i < toolbarLabels.length; i++) {
			ToolBarButton button = new ToolBarButton("files/icons/"
					+ imageFiles[i]);
			button.setToolTipText(toolbarLabels[i]);
			button.setMargin(margins);
			add(button);
			if (i == 3)
				addSeparator();
		}
		addListeners();
	}

	private void addListeners() {
		((ToolBarButton) getComponentAtIndex(0))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.openNewDialog();
					}
				});
		((ToolBarButton) getComponentAtIndex(1))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.openOpenDialog();
					}
				});
		((ToolBarButton) getComponentAtIndex(2))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.snimiAkcija();
					}
				});
		((ToolBarButton) getComponentAtIndex(3))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.openSaveDialog();
					}
				});
		((ToolBarButton) getComponentAtIndex(5))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.naPocetakAkcija();
					}
				});
		((ToolBarButton) getComponentAtIndex(6))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.korakNazadAkcija();
					}
				});
		((ToolBarButton) getComponentAtIndex(7))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.korakNapredAkcija();
					}
				});
		((ToolBarButton) getComponentAtIndex(8))
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menadzer.naKrajAkcija();
					}
				});
	}

	public void dozvoliOtvori() {
		getComponentAtIndex(1).setEnabled(true);
	}

	public void zabraniOtvori() {
		getComponentAtIndex(1).setEnabled(false);
	}

	public void dozvoliSnimi() {
		getComponentAtIndex(2).setEnabled(true);
		getComponentAtIndex(3).setEnabled(true);
	}

	public void zabraniSnimi() {
		getComponentAtIndex(2).setEnabled(false);
		getComponentAtIndex(3).setEnabled(false);
	}

	public void dozvoliNaPocetak() {
		getComponentAtIndex(5).setEnabled(true);
	}

	public void zabraniNaPocetak() {
		getComponentAtIndex(5).setEnabled(false);
	}

	public void dozvoliKorakNazad() {
		getComponentAtIndex(6).setEnabled(true);
	}

	public void zabraniKorakNazad() {
		getComponentAtIndex(6).setEnabled(false);
	}

	public void dozvoliKorakNapred() {
		getComponentAtIndex(7).setEnabled(true);
	}

	public void zabraniKorakNapred() {
		getComponentAtIndex(7).setEnabled(false);
	}

	public void dozvoliNaKraj() {
		getComponentAtIndex(8).setEnabled(true);
	}

	public void zabraniNaKraj() {
		getComponentAtIndex(8).setEnabled(false);
	}

}
